<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
function func_tpl_checklogin($params, $content, &$smarty, &$repeat) {
	if( isset($content) ) {
		if( $_SESSION['suser']->userid == 0 ) {
			return '';
		}
		return $content;
	}
}

function func_tpl_haslogin($params, $content, &$smarty, &$repeat) {
	if( isset($content) ) {
		if( isset($params['user']) ) {
			if( $params['user'] != $_SESSION['suser']->usertype ) {
				return '';
			}
		}
		if( $_SESSION['suser']->userid == 0 ) {
			return '';
		}
		return $content;
	}
}

function func_tpl_notlogin($params, $content, &$smarty, &$repeat) {
	if( isset($content) ) {
		if( isset($params['user']) ) {
			if( $params['user'] != $_SESSION['suser']->usertype ) {
				return $content;
			}
		}
		if( $_SESSION['suser']->userid == 0 ) {
			return $content;
		}
		return '';
	}
}

function func_tpl_pdprice($params, $content, &$smarty, &$repeat) {
	if( isset($content) ) {
		if( CONST_PRICE_MODE_TYPE == CONST_PRICE_MODE_UCT ) {
			global $ppmuctObj;
			
			$product = '';
			if( is_string($content) && strstr($content, '|') !== false ) {
				$ss = explode('|', $content);
				$product = array(
						'products_price' => $ss['0'],
						'products_price1' => $ss['1'],
						'products_price2' => $ss['2'],
						'products_price3' => $ss['3'],
						'products_price4' => $ss['4'],
						'products_price5' => $ss['5'],
						'categories_id' => $ss['6'],
							);
			} elseif( is_array($content) ) {
				$product = $content;
			}
			if( !is_object($ppmuctObj) ) {
				include_once(CONFIG_PATH . CONFIG_DIR_CLASSES . 'product.price.model.uct.class.php');
				$ppmuctObj = new ProductPriceModelUCTBase();
			}
			if( is_array($product) ) {//product data
				$ppmuctObj->setProduct($product);
				
				$content = $ppmuctObj->getProductPrice();
			}
		} else {
			if( $_SESSION['suser']->userid > 0 && $_SESSION['suser']->discount > 0 ) {
				$content = floatval($content) * (1-$_SESSION['suser']->discount);
			}
		}
		
		return $content;
	}
}

function func_tpl_outputfilter($content, &$smarty) {
	$pattern = $replace = array();
	$pattern[] = "/</head><body>/";
	$replace[] = "</head>\r\n<body>";
	/*
	if( preg_match('/<\/form(\s*)>/is', $content, $matches) ) {///<\/form(\s*)>/is
		$pattern[] = $matches['0'];
		
		$token = md5(PAGE_PARSE_START_TIME . 'TOKEN');
		$token_hidden = '<input type="hidden" name="token" value="' . $token . '">';
		$replace[] = $token_hidden . $matches['0'];
		
		$_SESSION['token'] = $token;
	}
	*/
	//
	$content = str_replace($pattern, $replace, $content);
	//$content = preg_replace("/([\r\n][\s]*)([<script.*?<\/script>]+)([\r\n]*)/", "\\2", $content);
	$content = preg_replace("/([\r\n]*)([<script.*?<\/script>]+)([\r\n]*)/", "\\2", $content);
	$content = preg_replace("/  /is", " ", $content);
	$content = preg_replace("/	/is", "", $content);
	$content = preg_replace("/<\/head><body/", "</head>\n<body", $content);
	$content = preg_replace("/<\/html>/", "</html>\n", $content);
	//$content .= "\r\n";
	
	return $content;
}

//
function func_tpl_title($prefix = '') {
	global $SETTINGS;
	
	//TITLE
	if( $SETTINGS['bs_company'] ) {
		$title = $SETTINGS['bs_company'];
	} elseif( defined('CONFIG_COMPANY_NAME') ) {
		$title = CONFIG_COMPANY_NAME;
	} else {
		$title = '';
	}
	if( $prefix != '' && $title != '' ) {
		$title = $prefix .'-' . $title;
	}
	
	return $title;
}

function func_tpl_cname($prefix = '') {
	global $SETTINGS;
	
	//CNAME
	if( $SETTINGS['bs_company'] ) {
		$cname = $SETTINGS['bs_company'];
	} elseif( defined('CONFIG_COMPANY_NAME') ) {
		$cname = CONFIG_COMPANY_NAME;
	} else {
		$cname = '';
	}
	if( $prefix != '' && $cname != '' ) {
		$cname = $prefix .'-' . $cname;
	}
	
	return $cname;
}

// Return tpl content with tpl file and its params
function func_get_tpl_content($tpl_file, $content_wrap = '', $context_wrap = '') {
	global $tpl;
	global $LANGUAGE;
	
	if( !util_not_null($tpl_file) ) {
		return false;
	}
	if( !util_not_null($content_wrap) ) {
		$content_wrap = array();
	}
	if( !util_not_null($context_wrap) ) {
		$context_wrap = array();
	}
	
	$tpl->assign("CONTENT", $content_wrap);
	$tpl->assign("CONTEXT", $context_wrap);
	$tpl->assign("LANGUAGE", $LANGUAGE);
	
	$content = $tpl->fetch($tpl_file);

	return $content;
}

//widget
function func_get_tpl_widget_content($tpl_file, $content_wrap = '', $context_wrap = '') {
	global $tpl;
	global $LANGUAGE;
	
	if( !util_not_null($tpl_file) ) {
		return false;
	}
	if( !util_not_null($content_wrap) ) {
		$content_wrap = array();
	}
	if( !util_not_null($context_wrap) ) {
		$context_wrap = array();
	}
	
	$tpl->assign("CONTENT", $content_wrap);
	$tpl->assign("CONTEXT", $context_wrap);
	$tpl->assign("LANGUAGE", $LANGUAGE);
	
	$content = $tpl->fetch($tpl_file);

	return $content;
}

//widget simple
function func_get_tpl_widget($tpl_file, $assign_keyvalues) {
	global $tpl;
	
	if( !util_not_null($tpl_file) ) {
		return false;
	}
	
	if( is_array($assign_keyvalues) ) {
		foreach($assign_keyvalues as $key => $value ) {
			if( !is_numeric($key) ) {
				$tpl->assign($key, $value);
			}
		}
	}
	//
	$content = $tpl->fetch($tpl_file);

	return $content;
}

////////////////////////////////////////////////////////////////////////
//pagelayout
//top
function func_get_pagelayout_top_content() {
	$content_wrap = array();
	$context_wrap = array(
			'TITLE' => TITLE,
			'CSS' => SYS_RT_URL_CSS . 'default.css',
			'URL' => CONFIG_URL_HTTP,
			'URL_PREFIX' => CONFIG_URL_PATH,
			'STYLE' => CONFIG_STYLE,
			'JSFILES' => array(
					//SYS_RT_URL_JS . 'calendar.js',
					SYS_RT_URL_JS . 'g.js',
						),
			'LOGO' => array(
					'image' => CONFIG_URL_HTTP . CONFIG_DIR_IMAGES . 'logo.gif',
					'title' => CONFIG_COMPANY_NAME,
					'link' => CONFIG_URL
						)
				);
	if( $_SESSION['user_login'] == 'true' ) {
		//$user = util_user_get_user($_SESSION['suser']['users_name'], 'users_name');
		//$user['users_image'] = CONFIG_URL_HTTP . CONFIG_DIR_IMAGES . 'users/' . $user['users_image'];
		$context_wrap = array_merge(
			$context_wrap,
			array(
				'user_login' => 'true',
				'CURRENT_USER' => $_SESSION['suser']['users_name'],
				'user' => $_SESSION['suser']
				)
				);
	}
	
	$content = func_get_tpl_content('pagelayout/pagelayout_top.tpl', $content_wrap, $context_wrap);
	
	return $content;
}

//
function func_get_tpl_cssstyles() {
	$cssstyles = array(
			SYS_RT_URL_CSS . 'g.css',
			SYS_RT_URL_CSS . 'l.css',
			SYS_RT_URL_CSS . 'c.css',
			//SYS_RT_URL_CSS . 'ddlevels.css',
			//SYS_RT_URL_JS . 'jscookmenu-2.0.3/ThemeLuGou/theme.css',
				);
	
	return $cssstyles;
}

//
function func_get_tpl_cssstyles_special() {
	$themecss = '';
	$stylesamplecss = '';
	
	/*
	//theme
	if( isset($_SESSION['styletheme']) ) {
		$themecss = CONFIG_URL_HTTP . CONFIG_DIR_STYLES . $_SESSION['styletheme']['path'] . '' . $_SESSION['styletheme']['link'] . '.css';
	} else {
		$themecss = SYS_RT_URL_CSS . 'd.css';
	}
	//
	if( isset($_SESSION['stylestatus']) && $_SESSION['stylestatus'] > 0 && isset($_SESSION['stylesamplecssfile']) ) {
		if( substr($_SESSION['stylesamplecssfile'], 0, strlen('blog#')) == 'blog#' ) {
			$stylesamplecss = CONFIG_URL_HTTP . 'styles/blog/' . substr($_SESSION['stylesamplecssfile'], strlen('blog#')) . 'stylesheet.css';
		} else {
			$stylesamplecss = CONFIG_URL_HTTP . 'style/' . $_SESSION['stylesamplecssfile'];
		}
	} else {
		$stylesamplecss = CONFIG_URL_HTTP . 'style/style_diy.css';
	}
	*/
	
	$cssfiles_special = array(
					array('css' => $themecss, 'id' => '_template_link'),
					array('css' => $stylesamplecss, 'id' => '_template_sample'),
						);
	
	return $cssfiles_special;
}

function func_get_tpl_jsfiles($request_type) {
	if( $request_type == 'admin' ) {
		$jsfiles = array(
				SYS_RT_URL_JS . 'common.js',
				SYS_RT_URL_JS . 'base.js',
				SYS_RT_URL_JS . 'ajax.js',
				SYS_RT_URL_JS . 'editor.js',
				//SYS_RT_URL_JS . 'calendar.js',
				//SYS_RT_URL_JS . 'utils.js',
				//SYS_RT_URL_JS . 'admin.js',
					);
	} else {
		$jsfiles = array(
				SYS_RT_URL_JS . 'common.js',
				SYS_RT_URL_JS . 'base.js',
				SYS_RT_URL_JS . 'ajax.js',
				//SYS_RT_URL_JS . 'calendar.js',
				//SYS_RT_URL_JS . 'utils.js',
				//SYS_RT_URL_JS . 'admin.js',
				//SYS_RT_URL_JS . 'ddlevels/ddlevelsmenu.js',
				//SYS_RT_URL_JS . 'jscookmenu-2.0.3/JSCookMenu.js',
				//SYS_RT_URL_JS . 'jscookmenu-2.0.3/ThemeLuGou/theme.js',
					);
	}
	
	return $jsfiles;
}

//pagelayout
function func_get_tpl_pagelayout_content($tpl_file, $content_wrap = '', $context_wrap = '', $type = 'main') {
	global $tpl;
	global $request_type, $request_link, $request_link_class, $request_link_subclass;
	global $messagestackObj;
	global $SETTINGS;
	global $LANGUAGE;
	
	//ajax
	if( isset($_REQUEST['ajax']) || isset($_REQUEST['xajax']) ) {
		exit();
	}
	
	//
	if( !util_not_null($tpl_file) ) {
		return false;
	}
	if( !util_not_null($content_wrap) ) {
		$content_wrap = array();
	}
	
	//TITLE
	if( $SETTINGS['bs_company'] ) {
		$title = $SETTINGS['bs_company'];
	} elseif( defined('CONFIG_COMPANY_NAME') ) {
		$title = CONFIG_COMPANY_NAME;
	} else {
		$title = '';
	}
	if( $SETTINGS['bs_company'] ) {
		$cname = $SETTINGS['bs_company'];
	} elseif( defined('CONFIG_COMPANY_NAME') ) {
		$cname = CONFIG_COMPANY_NAME;
	} else {
		$cname = '';
	}
	
	//STYLE CSS
	$cssfiles = func_get_tpl_cssstyles();
	$cssfiles_special = func_get_tpl_cssstyles_special();
	//JS FILES
	$jsfiles = func_get_tpl_jsfiles($request_type);
	
	//MESSAGESTACK
	$ms_size = $messagestackObj->size('header');
	$ms_content = $messagestackObj->output('header');
	
	//
	$context_base = array(
				'TITLE' => $title,
				'URL' => CONFIG_URL_HTTP,
				'URL_PREFIX' => CONFIG_URL_PATH,
				'URL_SUFFIX' => CONFIG_URL_SUFFIX,
				'STYLE' => CONFIG_STYLE,
				'CSSFILES' => $cssfiles,
				'CSSFILES_SPECIAL' => $cssfiles_special,
				'JSFILES' => $jsfiles,
				//
				'CNAME' => $cname,
				'user' => array(
						'id' => $_SESSION['suser']->userid,
						'firstname' => $_SESSION['suser']->lastname,
						'lastname' => $_SESSION['suser']->firstname,
						'name' => $_SESSION['suser']->username,
						'type' => $_SESSION['suser']->usertype,
						'discount' => $_SESSION['suser']->discount,
						'gid' => $_SESSION['suser']->usergid,
						'company' => $_SESSION['suser']->company,
							),
				'user_login' => (isset($_SESSION['user_login']) ? $_SESSION['user_login'] : 'false'),
				'request' => array(
						'type' => $request_type,
						'link' => $request_link,
						'class' => $request_link_class,
						'subclass' => $request_link_subclass,
							),
				'param' => $_GET,
				'messagestack' => array(
						'size' => $ms_size,
						'content' => $ms_content,
							),
						);
	if( $context_wrap == '' ) {
		$context_wrap = $context_base;
	} elseif( is_array($context_wrap) ) {
		$context_wrap = array_merge($context_base, $context_wrap);
	}
	
	//TYPE
	if( $type == 'admin' || $request_type == 'admin' ) {
		if( isset($SETTINGS['adminstyle']) && $SETTINGS['adminstyle'] != '' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . $SETTINGS['adminstyle'] . '.css';
		}
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'a.css';
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'admin.js';
	} elseif( $type == 'company' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'company.css';
		$context_wrap['CSSFILES_SPECIAL'] = array();
		$context_wrap['CSSFILES_SPECIAL'][] = array('css' => $themecss, 'id' => '_template_link');
	} elseif( $type == 'group' || $request_type == 'group' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'group.css';
		
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'group.js';
		if( isset($SETTINGS['style']) && $SETTINGS['style'] != '' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . $SETTINGS['style'] . '.css';
		} else {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'm.css';
		}
	} elseif( $type == 'item' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'citem.css';
		
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'citem.js';
	} else {
		if( isset($SETTINGS['style']) && $SETTINGS['style'] != '' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . $SETTINGS['style'] . '.css';
		} else {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'm.css';
		}
		if( $request_type == 'home' || $request_type == '' || $request_type == 'index' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'h.css';
		}
		if( $request_type == 'checkout' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'checkout.css';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'checkout.js';
		}
		if( $request_type == 'cart' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'cart.css';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'cart.js';
		}
		if( $request_type == 'popup' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'popup.css';
		}
		if( $request_type == 'my' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'my.css';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'my.js';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'pjs.my.js';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'pjs.my.dialog.js';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'pjs.my.rga.js';
		} elseif( CONST_CACHE_CONTROL_ENABLED == '2' ) {
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'load.js';
		}
		if( $request_type == 'member' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'member.css';
			$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'my.js';
		}
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'pjs.product.js';
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'pjs.user.js';
	}
	
	//js packer
	if( CONST_JS_PACKER == 'true' ) {
		$js_all = explode('|', CONST_JS_ALL);
		$js_allc = $context_wrap['JSFILES'];
		foreach($context_wrap['JSFILES'] as $k => $file) {
			if( in_array(basename($file), $js_all) ) {
				unset($context_wrap['JSFILES'][$k]);
			}
		}
		$context_wrap['JSFILES'] = array_values($context_wrap['JSFILES']);
		if( CONST_JS_V == '' ) {
			$js = SYS_RT_URL_JS . CONST_JS_GA;
		} else {
			$js = SYS_RT_URL_JS . CONST_JS_GA . '?v=' . CONST_JS_V;
		}
		array_unshift($context_wrap['JSFILES'], $js);
	}
	
	//
	global $injectObj;
	if( is_object($injectObj) ) {
		$content_data = $injectObj->get('func_get_tpl_pagelayout_content', 'content_wrap');
		if( is_array($content_data) ) {
			foreach($content_data as $k => $data) {
				$content_wrap = array_merge($content_wrap, $data);
			}
		}
		$context_data = $injectObj->get('func_get_tpl_pagelayout_content', 'context_wrap');
		if( is_array($context_data) ) {
			foreach($context_data as $k => $data) {
				$context_wrap = array_merge($context_wrap, $data);
			}
		}
	}
	
	//bc
	global $bcObj;
	$context_wrap['breadcrumb'] = $bcObj->toString();
	
	//ASSIGN
	$tpl->assign("CONTENT", $content_wrap);
	$tpl->assign("CONTEXT", $context_wrap);
	$tpl->assign("LANGUAGE", $LANGUAGE);
	$tpl->assign("SETTINGS", $SETTINGS);
	
	//CONTENT
	//$content = $tpl->fetch($tpl_file);
	$cache_id = $tpl->cache_id;
	if( $tpl_file == '' ) {
		$tpl_file = $tpl->tpl_file;
	}
	if( $tpl->caching == false ) {
		$content = $tpl->fetch($tpl_file);
	} else {
		if( strlen($cache_id) == 0 ) {
			$tpl->setCacheID();
			$cache_id = $tpl->cache_id;
		}
		$content = $tpl->fetch($tpl_file, $cache_id);
	}
	
	return $content;
}

function func_get_tpl_pagelayout_content_company($tpl_file, $content_wrap = '', $context_wrap = '') {
	$content = func_get_tpl_pagelayout_content($tpl_file, $content_wrap, $context_wrap, 'company');
	
	return $content;
}

function func_get_tpl_pagelayout_content_download($tpl_file, $content_wrap = '', $context_wrap = '') {
	global $injectObj;
	if( is_object($injectObj) ) {
		$content_data = $injectObj->get('func_get_tpl_pagelayout_content_download', 'content_wrap');
		if( is_array($content_data) ) {
			foreach($content_data as $k => $data) {
				$content_wrap = array_merge($content_wrap, $data);
			}
		}
		$context_data = $injectObj->get('func_get_tpl_pagelayout_content_download', 'context_wrap');
		if( is_array($context_data) ) {
			foreach($context_data as $k => $data) {
				$context_wrap = array_merge($context_wrap, $data);
			}
		}
	}
	//
	$content = func_get_tpl_pagelayout_content($tpl_file, $content_wrap, $context_wrap, 'download');
	
	return $content;
}

function func_get_tpl_pagelayout_content_product($tpl_file, $content_wrap = '', $context_wrap = '') {
	global $injectObj;
	if( is_object($injectObj) ) {
		$content_data = $injectObj->get('func_get_tpl_pagelayout_content_product', 'content_wrap');
		if( is_array($content_data) ) {
			foreach($content_data as $k => $data) {
				$content_wrap = array_merge($content_wrap, $data);
			}
		}
		$context_data = $injectObj->get('func_get_tpl_pagelayout_content_product', 'context_wrap');
		if( is_array($context_data) ) {
			foreach($context_data as $k => $data) {
				$context_wrap = array_merge($context_wrap, $data);
			}
		}
	}
	//
	$content = func_get_tpl_pagelayout_content($tpl_file, $content_wrap, $context_wrap, 'product');
	
	return $content;
}

// Editor
function func_get_tpl_pagelayout_content_editor($tpl_file, $content_wrap = '', $context_wrap = '', $type = '', $editor_param = '') {
	global $tpl;
	global $request_type, $request_link, $request_link_class, $request_link_subclass;
	global $messagestackObj;
	global $SETTINGS;
	global $LANGUAGE;
	
	if( !util_not_null($tpl_file) ) {
		return false;
	}
	if( !util_not_null($content_wrap) ) {
		$content_wrap = array();
	}
	
	//TITLE
	if( $SETTINGS['bs_company'] ) {
		$title = $SETTINGS['bs_company'];
	} elseif( defined('CONFIG_COMPANY_NAME') ) {
		$title = CONFIG_COMPANY_NAME;
	} else {
		$title = '';
	}
	if( $SETTINGS['bs_company'] ) {
		$cname = $SETTINGS['bs_company'];
	} elseif( defined('CONFIG_COMPANY_NAME') ) {
		$cname = CONFIG_COMPANY_NAME;
	} else {
		$cname = '';
	}
	
	//STYLE CSS
	$cssfiles = func_get_tpl_cssstyles();
	$cssfiles_special = func_get_tpl_cssstyles_special();
	//JS FILES
	$jsfiles = func_get_tpl_jsfiles($request_type);
	
	//MESSAGESTACK
	$ms_size = $messagestackObj->size('header');
	$ms_content = $messagestackObj->output('header');
	
	//$jsblock = func_editor_init(false);
	if( is_array($editor_param) ) {
		if( $editor_param['type'] == 'simple' ) {
			$jsblock = func_editor_init(false);
		} elseif( $editor_param['type'] == 'exact' ) {
			$elements = array('field_introtext, field_fulltext, field_description');
			$jsblock = func_editor_init('exact', $elements);
		} elseif( $editor_param['type'] == 'advanced' ) {
			$jsblock = func_editor_init('advanced');
		}
	} else {
		$elements = array('field_introtext, field_fulltext, field_description');
		$jsblock = func_editor_init('exact', $elements);
	}
	
	//
	$context_wrap = array(
				'TITLE' => $title,
				'URL' => CONFIG_URL_HTTP,
				'URL_PREFIX' => CONFIG_URL_PATH,
				'URL_SUFFIX' => CONFIG_URL_SUFFIX,
				'STYLE' => CONFIG_STYLE,
				'CSSFILES' => $cssfiles,
				'CSSFILES_SPECIAL' => $cssfiles_special,
				'JSFILES' => $jsfiles,
				'JSBLOCK' => $jsblock,
				//
				'CNAME' => $cname,
				'user' => array(
						'id' => $_SESSION['suser']->userid,
						'name' => $_SESSION['suser']->username,
						'type' => $_SESSION['suser']->usertype,
						'gid' => $_SESSION['suser']->usergid,
							),
				'user_login' => (isset($_SESSION['user_login']) ? $_SESSION['user_login'] : 'false'),
				'request' => array(
						'type' => $request_type,
						'link' => $request_link
							),
				'param' => $_GET,
				'messagestack' => array(
						'size' => $ms_size,
						'content' => $ms_content,
							),
						);
	if( $context_wrap == '' ) {
		$context_wrap = $context_base;
	} elseif( is_array($context_wrap) ) {
		$context_wrap = array_merge($context_base, $context_wrap);
	}
	
	//TYPE
	if( $type == 'admin' || $request_type == 'admin' ) {
		if( isset($SETTINGS['style']) && $SETTINGS['style'] != '' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . $SETTINGS['style'] . '.css';
		}
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'a.css';
	} elseif( $type == 'company' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'company.css';
		$context_wrap['CSSFILES_SPECIAL'] = array();
		$context_wrap['CSSFILES_SPECIAL'][] = array('css' => $themecss, 'id' => '_template_link');
	} elseif( $type == 'group' || $request_type == 'group' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'group.css';
		
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'group.js';
	} elseif( $type == 'item' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'citem.css';
		
		$context_wrap['JSFILES'][] = SYS_RT_URL_JS . 'citem.js';
	} elseif( $request_type == 'home' || $request_type == '' || $request_type == 'index' ) {
		$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'h.css';
	} else {
		if( isset($SETTINGS['style']) && $SETTINGS['style'] != '' ) {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . $SETTINGS['style'] . '.css';
		} else {
			$context_wrap['CSSFILES'][] = SYS_RT_URL_CSS . 'm.css';
		}
	}
	
	//
	global $injectObj;
	if( is_object($injectObj) ) {
		$content_data = $injectObj->get('func_get_tpl_pagelayout_content', 'content_wrap');
		if( is_array($content_data) ) {
			foreach($content_data as $k => $data) {
				$content_wrap = array_merge($content_wrap, $data);
			}
		}
		$context_data = $injectObj->get('func_get_tpl_pagelayout_content', 'context_wrap');
		if( is_array($context_data) ) {
			foreach($context_data as $k => $data) {
				$context_wrap = array_merge($context_wrap, $data);
			}
		}
	}
	
	//
	$tpl->assign("CONTENT", $content_wrap);
	$tpl->assign("CONTEXT", $context_wrap);
	$tpl->assign("LANGUAGE", $LANGUAGE);
	$tpl->assign("SETTINGS", $SETTINGS);
	
	$content = $tpl->fetch($tpl_file);

	return $content;
}

function func_get_tpl_pagelayout_content_editor_common($tpl_file, $content_wrap = '', $context_wrap = '') {
	$content = func_get_tpl_pagelayout_content_editor($tpl_file, $content_wrap, $context_wrap, 'common', 'common');
	
	return $content;
}
//
?>